package studio.wetrack.accountService.auth.domain;

import studio.wetrack.accountService.RoleGroupInterface;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by chen on 2018/6/13.
 * 例子
 */
public enum RoleGroup implements RoleGroupInterface {

    CUSTOMER("客户监控员", new Role[]{
            Role.DEFAULT
    });

    String name;
    Role[] roles;

    RoleGroup(String name, Role[] roles){
        this.name = name;
        this.roles = roles;
    }
    public String getName(){
        return name;
    }

    public Role[] getRoles() {
        return roles;
    }

    @Override
    public String[] getRolesStringArray(){
        String[] rolesStringArray = new String[roles.length];
        for(int i = 0; i < roles.length; i++){
            rolesStringArray[i] = roles[i].getRoleName();
        }
        return rolesStringArray;
    }

    @Override
    public List<RoleClass> getRoleClassList(){
        List<RoleClass> list = new ArrayList<RoleClass>();
        for(int i = 0; i < roles.length; i++){
            RoleClass roleClass = new RoleClass();
            roleClass.setRoleName(roles[i].getRoleName());
            roleClass.setDesc(roles[i].getDesc());
            list.add(roleClass);
        }
        return list;
    }

    @Override
    public RoleGroupClass enumToClass(){
        RoleGroupClass roleGroupClass = new RoleGroupClass();
        roleGroupClass.setName(this.getName());
        roleGroupClass.setRoleList(getRoleClassList());
        return roleGroupClass;
    }


}
